﻿using Company.Main;
using Company.Share.Prism;
using Company.Shell.Views;
using Company.Hardware.Acs;
using System.Configuration;
using System.Data;
using System.Windows;
using Company.Core;
using Company.Axis;
using Company.Logger;
using Company.UI;
using Company.IO;
using Company.Config;
using Company.Communication.Serial;
using System.Diagnostics;
using Company.Dialog;

namespace Company.Shell
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        public new MainWindow MainWindow { get;private set; }
        protected override void OnStartup(StartupEventArgs e)
        {
            // 全局异常捕获
            AppDomain.CurrentDomain.UnhandledException += (s,e) =>
            {
                Exception ex = (Exception)e.ExceptionObject;
                Debug.WriteLine($"{ex.Message}");
            };
            // 文本框双向绑定无法输入小数点
            FrameworkCompatibilityPreferences.KeepTextBoxDisplaySynchronizedWithTextProperty = false;
            base.OnStartup(e);
        }
        protected override Window CreateShell()
        {
            return MainWindow;
        }
        /// <summary>
        /// 注册类型
        /// </summary>
        /// <param name="containerRegistry"></param>
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            MainWindow = new MainWindow();
            // 注册主窗体
            containerRegistry.RegisterInstance<Window>(MainWindow,ViewNames.MainWindow);
        }
        /// <summary>
        /// 配置模块目录
        /// </summary>
        /// <param name="moduleCatalog"></param>
        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            base.ConfigureModuleCatalog(moduleCatalog);
            moduleCatalog.AddModule<CompanyConfigModule>();//添加配置文件模块
            moduleCatalog.AddModule<CompanyHardwareAcsModule>();//添加Acs控制器模块
            moduleCatalog.AddModule<CompanyCoreModule>();//添加Acs控制器模块
            moduleCatalog.AddModule<CompanySerialModdule>();//添加串口通讯模块
            moduleCatalog.AddModule<CompanyMainModule>();//添加主模块
            moduleCatalog.AddModule<CompanyAxisModule>();//添加Axis模块
            moduleCatalog.AddModule<CompanyIOModule>();//添加Axis模块
            moduleCatalog.AddModule<CompanyLoggerModule>();//添加日志模块
            moduleCatalog.AddModule<CompanyUIModule>();//添加UI模块
            moduleCatalog.AddModule<CompanyDialogModule>();//添加Dialog模块
        }
        /// <summary>
        /// 创建模块目录
        /// </summary>
        /// <returns></returns>
        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog() { ModulePath = ModuleNames.ModulePath };//配置本地模块目录
        }
    }

}
